#ifndef DICO_H
#define DICO_H

#include "config.h"

#include <QObject>
#include <QHash>
#include <QSet>
#include <QStringList>
#include <QRegExp>
#include <QLocale>
#include <QProgressBar>
#include <QTime>
#include <QPainter>

#include "ppjtools.h"


//-------------------------
class Dico : public QObject
{
        Q_OBJECT

    private:
        QTime m_calcTime;
        int m_calcStep;
        bool m_useDamerauTest;
//        QVector<QString> m_contentList;
        QStringList m_contentList;

        int m_maxItems;

        QHash<QString, QString> m_convertionTable;

        QString normalize (const QString& test);

        QString m_currentRefDico;

        void dicoStats ();

        static QString separators () { return "/ ["; }
        static QIcon languageIcon (const QString &language);
        static QString languageString (const QString & name);
        static QIcon personalDicIcon ();

    public:
        explicit Dico (QObject *parent, bool damerau);

        QHash<QString, QString>	decomp (const QString &word);
        bool	isValid () { return not m_contentList.isEmpty (); }
        int		size () { return m_contentList.size (); }
        void	init (const QString& path, bool keepAnnexe = true);

        enum { StartsWith,
               EndsWith,
               Contains,
               NotContains,
               ContainsAllLetters,
               ContainsNoLetter,
               LeMotLePlusLong,
               Anagrams,
               LookingLike,
               DistantFrom,
               Jokers,
               RegExp };

        QString currentRefDico () { return m_currentRefDico; }

        int		averageLength ();

        void	beginCalc (const int max = 0);
        void	updateCalc (int index = 0);
        void	endCalc ();

        inline bool dicsContains (const QString& word) { return m_contentList.contains (word); }

        static	QMap<QString, QIcon> refDicosList();
        static	QStringList officialRefDicosList();

    signals:
        void	message (QString);
        void	error (QString);
        void	warning (QString);
        void	dicoInfos (int min, int max);
        void	xMessage (bool extended, QStringList result, QString txt = QString ());
        void	initCalc (int maxSteps);
        void	progress (int step);
        void	stopCalc (int);

    public slots:
        void	clear ();

        void	find (const QString & target, int mode, int distMax = -1);
        void	find (const QRegExp & target, bool extended);
        void	find (const QString & target, bool anyLength);

        void	loadFrom (const QString & fileName);
        void	addFrom (const QString & fileName, bool isTrusty = false);
        void	save (const QString & path);
        void	addToAnnexe (const QString & word);
};


#endif // DICO_H
